<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\SwtNetworkChain;
use App\Models\SwtMarketChains;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class SwtNetworkChainController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(\App\Models\SwtNetworkChain::with(['chain','network']), function (Grid $grid) {

            $grid->column('id')->sortable();
            $grid->column('network.icon','网络图标') -> image(config('app.url').'/storage', 50, 50);
            $grid->column('network.network_name','网络名称');
            $grid->column('chain.icon','币种图标')->image(config('app.url').'/storage', 50, 50);
            $grid->column('chain.base_ccy','币种名称');
            $grid->column('default_add','默认增加') -> switch();
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->selector(function (Grid\Tools\Selector $selector) {
                $selector->select('default_add', '默认增加', ['否','是']);
            });

            $grid->disableActions();
            $grid->disableCreateButton(); //关闭新增按钮

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->like('chain.base_ccy','网络名称');
                $filter->like('network.name','币种名称');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SwtNetworkChain(), function (Show $show) {
            $show->field('id');
            $show->field('network_id');
            $show->field('chain_id');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SwtNetworkChain(), function (Form $form) {
            $form->display('id');
            $form->text('network_id');
            $form->text('chain_id');
            $form->text('default_add');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
